package core.resources
{
import core.service.Service;
import core.service.ServiceRequest;

import values.shop.ShopConfigValue;
import values.shop.ShopItemValue;

/**
 * ShopResourceTask
 * @author jliang
 *
 */
public class ShopResourceTask extends LoadTaskBase
{
    //==========================================================================
    //  Constructor
    //==========================================================================
    public function ShopResourceTask()
    {
        super();
    }
    
    override public function start():void
    {
        Service.invoke(new ServiceRequest("shop_check_limit", null, syncUpResponseHandler));
    }
    
    private function syncUpResponseHandler(data:Object):void
    {
        var globalData:Object = data.global;
        var playerData:Object = data.player;
        
        var shopItemKey:String;
        var shopItem:ShopItemValue;
        
        for (shopItemKey in globalData)
        {
            shopItem = ShopConfigValue.getShopItemByKey(shopItemKey);
            shopItem.totalRestNum = int(globalData[shopItemKey]);
        }
        
        for (shopItemKey in playerData)
        {
            shopItem = ShopConfigValue.getShopItemByKey(shopItemKey);
            shopItem.todayRestNum = shopItem.dailyLimit - int(playerData[shopItemKey]);
        }
        
        this.complete();
    }
}
}